﻿#include "mgd_car_object.h"

mGD_car_object::mGD_car_object(mGD_car_object *parent)
    : MBaseObject (parent)
{
    this->setZValue(-5);
    CarNumberItem = new QGraphicsTextItem("GD***" , this);
    QFont font = CarNumberItem->font();
    font.setBold(true);
    font.setFamily("Times New Roman");
    CarNumberItem->setFont(font);
    CarNumberItem->setPos(-4,75);
    CarNumberItem->setRotation(-90);

    socketFrontLeft = new SocketObject(this,CarNumberItem,getCarIP());
    socketFrontLeft->SocketID("KFL");
    socketFrontLeft->socketNumber("1");
    socketFrontLeft->setPos(40, 70);

    socketMiddleLeft = new SocketObject(this,CarNumberItem,getCarIP());
    socketMiddleLeft->SocketID("KML");
    socketMiddleLeft->socketNumber("2");
    socketMiddleLeft->setPos(75, 70);

    socketMiddleRight = new SocketObject(this,CarNumberItem,getCarIP());
    socketMiddleRight->SocketID("KMR");
    socketMiddleRight->socketNumber("5");
    socketMiddleRight->setPos(75, 25);

    plugFrontRight = new PlugObject(this,CarNumberItem,getCarIP());
    plugFrontRight->PlugID("TFR");
    plugFrontRight->plugNumber("4");
    plugFrontRight->setPos(40,25);

    plugBackLeft = new PlugObject(this,CarNumberItem,getCarIP());
    plugBackLeft->PlugID("TBL");
    plugBackLeft->plugNumber("3");
    plugBackLeft->setPos(115, 70);
    plugBackLeft->setRotation(-90);

    plugBackRight = new PlugObject(this,CarNumberItem,getCarIP());
    plugBackRight->PlugID("TBR");
    plugBackRight->plugNumber("6");
    plugBackRight->setPos(115, 25);
    plugBackRight->setRotation(-90);

}

mGD_car_object::~mGD_car_object()
{

}

QRectF mGD_car_object::boundingRect() const
{
    return QRectF(0,0,140,90);
}

void mGD_car_object::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option); Q_UNUSED(widget);

    //车的外观
    QRectF squareRect_head = QRectF(0,15,20,60);
    QRectF squareRect_back = QRectF(20,0,120,90);
    QPen pen(QColor(237, 125, 49), 2, Qt::SolidLine);
    painter->setPen(pen);
    painter->drawRect(squareRect_head);
    painter->drawRect(squareRect_back);


    if(this->isSelected())
        drawSelectedRect(painter);
}

